<script setup>
import { ref,onMounted } from "vue";
import { useRouter, useRoute } from "vue-router";
import requestUtil from "@/utils/request.js";
import Cookies from "js-cookie";
let router = useRouter();
let route = useRoute();
let chosenAddressId = ref(1);
let addressList = ref([]);
const getAddressList = async () => {
  let res = await requestUtil.post("/app/address/", {
    userId: Cookies.get("userId")
  });
  addressList.value = res.data.data;
};
onMounted(() => {
  getAddressList();
})
const onAdd = item => {
  router.push({
    path: "/addressadd",
    query: {
      userId: Cookies.get("userId")
    }
  });
};
const onEdit = item => {
  router.push({
    path: "/addresschange",
    query: {
      id: item.id
    }
  });
};
const onClickLeft = () => history.back();
</script>

<template>
  <div class="address">
    <van-nav-bar
      title="我的收获地址"
      left-text="返回"
      left-arrow
      @click-left="onClickLeft"
    />
    <van-address-list v-model="chosenAddressId" :list="addressList" @add="onAdd" @edit="onEdit" />
  </div>
</template>

<style scoped>
</style>